package com.twl.ws.aspect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component  
@Aspect
public class FacadeAspect {
	private Logger log = Logger.getLogger(FacadeAspect.class);
	@Pointcut("execution(* com.twl.ws.web..*.*(..))")
	private void anyMethod(){}
//	@After("anyMethod()")
//	public void doAfter(JoinPoint joinPoint) throws Exception {  
//		Object[] args = joinPoint.getArgs();
//		log.info("[请求的类]："+joinPoint.getTarget().getClass().getName());
//		log.info("[请求的方法]："+joinPoint.getSignature().getName());
//		for(int i=0;i<args.length;i++){
//			if(args[i] instanceof String){
//				log.info("[请求的参数][arg"+i+"]::["+args[i]+"]");
//			}else{
//				log.info("[请求的参数][arg"+i+"]:");
//				Class c = args[i].getClass();  
//		        Field field[] = c.getDeclaredFields();  
//		        for (Field f : field) {
//		        	if("serialVersionUID".equals(f.getName()))
//		        		continue;
//		        	if("goodsElement".equals(f.getName())){
//		        		if(invokeMethod(args[i], f.getName(), null)!=null){
//		        			Object childObj = invokeMethod(args[i], f.getName(), null);
//			        		Class childclass = invokeMethod(args[i], f.getName(), null).getClass();
//			        		field = childclass.getDeclaredFields();  
//					        for (Field f1 : field) {  
//					            Object v = invokeMethod(childObj, f1.getName(), null);  
//					            log.info("["+f1.getName()+"]:" + "["+v+"]");  
//					        } 
//		        		}
//				        continue;
//		        	}
//		            Object v = invokeMethod(args[i], f.getName(), null);  
//		            log.info("["+f.getName()+"]:" + "["+v+"]");  
//		        }  
//		        Class superclass = c.getSuperclass();  
//		        if (superclass != null) {  
//		        	field = superclass.getDeclaredFields();  
//			        for (Field f : field) {  
//			        	if("serialVersionUID".equals(f.getName()))
//			        		continue;
//			            Object v = invokeMethod(args[i], f.getName(), null);  
//			            log.info("["+f.getName()+"]:" + "["+v+"]");  
//			        }   
//		        }  
//			}
//		}
//    }  
	
	/** 
     * 获得对象属性的值 
     */  
    @SuppressWarnings("unchecked")  
    private Object invokeMethod(Object owner, String methodName,  
            Object[] args) throws Exception {  
        Class ownerClass = owner.getClass();  
        methodName = methodName.substring(0, 1).toUpperCase()  
                + methodName.substring(1);  
        Method method = null;  
        try {  
            method = ownerClass.getMethod("get" + methodName);  
        } catch (SecurityException e) {  
        } catch (NoSuchMethodException e) {  
            return " can't find 'get" + methodName + "' method";  
        }  
        return method.invoke(owner);  
    } 
    
    
  
}
